home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / cp1.zip / DISKTYPE.C < prev    next >
C/C++ Source or Header  |  1993-05-24  |  5KB  |  125 lines

  1. ===========================================================================
  2.  BBS: The Abacus * HST/DS * Potterville MI
  3. Date: 05-18-93 (21:26)             Number: 32
  4. From: SVEN VAN DE VELDE            Refer#: NONE
  5.   To: NEIL CUNNINGHAM               Recvd: NO  
  6. Subj: HARD DRIVE IDENTITY            Conf: (36) C Language
  7. ---------------------------------------------------------------------------
  8. Hi Neil,
  9.  
  10.  NC> I'm kinda new to C so, I need some help.  I'm trying to write a simple
  11.  NC> program that will determine all the hardware installed on any
  12.  NC> computer. The
  13.  NC> only problem I've run into is that I can't figure out how to extract
  14.  NC> the hard
  15.  NC> drive types from CMOS. Any help would greatly appreciated. This is the
  16.  NC>  beginning of what might be a rather large project for the U.S. Navy
  17.  NC> (which I
  18.  NC>  am in) to assist in ADP security. Again Thanks in advance!
  19.  
  20.  
  21.  
  22.  Try BIOS interrupt 11h.
  23.  
  24.  It returns a 16 bit value in the AX register.
  25.  
  26.  bitnr.
  27.  
  28.  0              equals 1 if the system has one or more disk drives.
  29.  1              not used.
  30.  2 and 3        the amount of RAM on the main board.
  31.                 00 = 16KB
  32.                 01 = 32KB
  33.                 10 = 48KB
  34.                 11 = 64KB
  35.  4 and 5        screen mode at startup.
  36.  6 and 7        amound of disk drives if bit 0 is set!
  37.                                       ---------------
  38.                 00 = 1 disk
  39.                 01 = 2 disks
  40.                 10 = 3 disks
  41.                 11 = 4 disks
  42.  
  43.  Now, how do you determine WHICH hard drive is attached? Well, use the
  44.  interrupt service routine 41h (for hard disk 0) or 46h (for hard disk 1)
  45.  of BIOS.  These interrupts are pointing to a table that describes the
  46.  contents concerning the hard disks. The BIOS knows lots of these tables
  47.  standardly, so that BIOS adapt the hard disk available at startup.
  48.  Sadly, I don't know how the the processor registers or memory react at these
  49.  interrupt functions. (The information in my book isn't detailed for
  50.  security reasons. Hard disk crashes etc.)
  51.  But I hope that this is a start for more searching.
  52.  Or try this routine...
  53.  
  54.  /* DISKTYPE.C *****************************************************
  55.     program to get disk information via BIOS call 0x440d, minor
  56.     function 0x60, compile with byte alignment option in Zortech for
  57.     example ZTC -a1 disktype
  58.     ****************************************************************/
  59. #include <dos.h>
  60. #include <stdlib.h>
  61.  
  62. #include <stdio.h>
  63.  
  64. main(int argc, char *argv[])
  65. {
  66.     struct {
  67.         char    SpecialFunction;
  68.         char    DeviceType;
  69.         int     DeviceAttributes;
  70.         int     Cylinders;
  71.         char    MediaType;
  72.         int     BytesPerSector;         /* bpb begins */
  73.         char    SectorsPerCluster;
  74.         int     ReservedSectors;
  75.         char    NumberOfFATs;
  76.         int     RootDirEntries;
  77.         int     Sectors;
  78.         unsigned char    MediaDescriptor;
  79.         int     FATSectors;
  80.         int     SecPerTrack;
  81.  
  82.         int     Heads;
  83.         long    HiddenSectors;
  84.         long    HugeSectors;            /* used if Sectors returns 0 */
  85.     } bpbstruc;
  86.     union REGS r;
  87.     struct SREGS s;
  88.     char *errors[] = {"Invalid function request",
  89.                       "Invalid drive ID",
  90.                       " ",
  91.                       " ",
  92.                       "Access denied"};
  93.     int drive = 0;              /* default drive */
  94.     if (argc < 2)              /* no drive specified */
  95.     {
  96.         printf("Error: no drive specified.\n");
  97.         printf("Usage: disktype <drive>\n");
  98.         return(1);
  99.     }
  100.     /* make upper case */
  101.  
  102.     drive =(argv[1][0] >= 'a' && argv[1][0] <= 'z') ?
  103.                 argv[1][0] - 'a' + 'A' : argv[1][0];
  104.     drive -= 'A' - 1;       /* 1 = A, 2 = B . . . */
  105.     r.x.ax = 0x440d;              /* function call */
  106.     r.x.bx = drive;               /* drive identifier */
  107.     r.x.cx = 0x0860;           /* minor function 60, ch must = 8*/
  108.     r.x.dx = (unsigned int) &bpbstruc;      /* offset of struct */
  109.     s.ds = (unsigned int)((long) &bpbstruc>>16);   /* segment of struct */
  110.     intdosx(&r,&r,&s);
  111.  
  112.     /* now you should be able to read the info if there were no errors */
  113.     /* check the carry flag, and if set, error number is returned in AX */
  114.     if (r.x.cflag != 0)
  115.         printf("Error %d: %s",r.x.ax,errors[r.x.ax]);
  116.     else
  117.     {
  118.         printf("Information for drive %c\n",drive + 'A' - 1);
  119.         printf("Special function: %d\n", bpbstruc.SpecialFunction);
  120.  --- TBBS v2.1/NM
  121.  * Origin: Autodesk Global Village (1:125/289)
  122. SEEN-BY: 1/211 11/2 4 13/13 101/1 108/89 109/25 110/69 114/5 123/19 124/1
  123. SEEN-BY: 153/752 154/40 77 157/2 159/100 125 575 950 203/23 209/209 261/1023
  124. SEEN-BY: 280/1 390/1 396/1 5 15 2270/1 2440/5 3603/20
  125.